int strToInt(char* str){
    int i = 0, j = strlen(str)-1;
    while (str[i] == ' ') i++;
    int sign = 1;   //正负符号
    if (str[i] == '-' || str[i] == '+') {
        if (str[i] == '-') sign = -1;
        i++;
    }
    while (str[i] == '0') i++;  //去掉前导零
    if ( !(str[i] >= '0' && str[i] <= '9')) return 0;  //illegal


    long long res = 0;  //注意使用的数据类型，不能用uint32_t
    while (i <= j) {
        if (str[i] >= '0' && str[i] <= '9') {
            res = res*10 + str[i] - '0';

            // 溢出后立即返回，后面的计算没有意义，且可能超过long long范围
            if (sign == 1 && res >= INT_MAX) return INT_MAX;
            else if (sign == -1 && (-res) <= INT_MIN) return INT_MIN;

            i++;
        } else {
            break;
        }
    }
    return (sign == 1)? res:(-res);
}